# include <stdio.h>
#include<malloc.h>
#include<stdlib.h>
// function to find maximum and minimum element
void maxmin(int arr[],int n)
{
int max,min,i;
max=arr[0];
min=arr[0];
for(i=0;i<n;i++)
{
if (max<arr[i])
	max=arr[i];
if (min>arr[i])
	min=arr[i];
}
printf("the maximum no is: %d \n",max);
printf("the minimum no is: %d \n",min);
}

// func to find count of a element
int count(int arr[],int n)
{
int x,i,counter=0;
printf("enter the element of which u want the count \n");
scanf("%d",&x);
for(i=0;i<n;i++)
{
if (x==arr[i])
{	
counter++;

}
}
return counter;
}

// func to find index of a given element
int index(int arr[],int n)
{
int x,i,counter;
printf("enter the element of which u want the index \n");
scanf("%d",&x);
for (i=0;i<n;i++)
{
if(x==arr[i])
{
	counter=i;
	break;
}
}
return counter;
}

// func to reverse a given array
void reverse(int arr[], int n)
{
int i,j,k;
for (i=0,j=n-1;i<n/2,j>=n/2;i++,j--)
{
k=arr[i];
arr[i]=arr[j];
arr[j]=k;
}

}

// func to sort an array
void sort(int arr[], int n)
{
int i,j,temp;
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(arr[i]>arr[j])
{
temp=arr[i];
arr[i]= arr[j];
arr[j]=temp;
}
}
}

}

// func to append a value in array
int *app(int *arr,int n)
{
int i,*arr2;
arr2=malloc((n+1)*sizeof(int));
for(i=0;i<n;i++)
{
*(arr2+i)=*(arr+i);
}
printf("eneter the value u want to append\n");
scanf("%d",(arr2+i));
return arr2;
}

// func to insert a value at a given position
int *insert(int *arr,int n)
{
int i,*arr2,counter;
arr2=malloc((n+1)*sizeof(int));
printf("enter the position u want to insert \n");
scanf("%d",&counter);
for(i=0;i<n;i++)
{
if ( counter==i)
	break;
else
*(arr2+i)=*(arr+i);
}
printf("eneter the value u want to insert\n");
scanf("%d",(arr2+counter));
while(i<n)
{
*(arr2+(i+1))=*(arr+i);
i++;
}
return arr2;
}
// program to extend a list
int *extend(int *arr0,int *arr1,int n1,int n2)
{
int i=0,*arr2,counter;
arr2=malloc((n1+n2)*sizeof(int));
while(i<n1)
{
*(arr2+i)=*(arr0+i);
i++;
}
for(i=0;i<n2;i++)
{
*(arr2+n1+i)=*(arr1+i);
}
return arr2;
}

// func to delete a given element
int remove1 (int arr[], int n,int x)
{
int i,counter=0,j;
for(i=0;i<n;i++)
{
if(arr[i]==x)
	{counter=1;
	for(j=i;j<n-1;j++)
	{
	arr[j]=arr[j+1];
	}
	break;}
}


return counter;
}

// func to delete an element at a given index
void delete (int arr[], int n,int in)
{
int i,j;
for(i=0;i<n;i++)
{
if(i == in)
	{
	for(j=i;j<n-1;j++)
	{
	arr[j]=arr[j+1];
	}
	break;}
}

}
void main()
{
int k, n, arr[50],i,j,l,*ptr;
int n1, arr1[50],counter;
printf("enter the length of array \n");
scanf("%d",&n);
printf("enter the elements of array \n");

for(j=0;j<n;j++)
scanf("%d",&arr[j]);
printf("enter 0 to count,1 to find index,2 to reverse,3 to sort,4 to append ,5 to insert,6 to extend,7 to remove a given element,8 to delete a given element at a given position\n");
scanf("%d",&l);


switch(l)
{
case 0:
printf ("\n the count of element is %d ",count (arr,n));
break;

case 1:
printf(" \n the index of element is %d ",index(arr,n));
break;

case 2:
reverse(arr,n);
printf("the elements of reversed array:\n");
for(i=0;i<n;i++)
printf("%d",arr[i]);
break;

case 3:
sort(arr,n);
printf("the elements of sorted array are:\n");
for(i=0;i<n;i++)
printf("%d",arr[i]);
break;

case 4:
ptr=app(arr,n);
printf("the elements of appended array are: \n");
for(i=0;i<=n;i++)
printf("%d\n",ptr[i]);
break;

case 5:
ptr=insert(arr,n);
printf("the elements of array after insrtion are: \n");
for(i=0;i<=n;i++)
printf("%d",ptr[i]);
break;

case 6:
printf("enter the length of other array \n");
scanf("%d", &n1);
printf("enter the values of other array \n");
for(i=0;i<n1;i++)
scanf("%d",&arr1[i]);
ptr=extend(arr,arr1,n,n1);
printf("the elements of extended list are:\n");
for(i=0;i<n+n1;i++)
printf("%d\n",ptr[i]);
break;

case 7:
printf("enter the element u want to delete \n");
scanf("%d",&n1);
counter=remove1(arr,n,n1);
if(counter==0)
printf("element is absent in the array \n");
else
{
n=n-1;
printf("the elements of array are:\n");
for(i=0;i<n;i++)
printf("%d\n",arr[i]);
}
break;


case 8:
printf("enter the position at which u want to delete element from array \n");
scanf("%d",&n1);
if(n1>n)
	printf("index should not exceed the size of array \n");
else
	{delete(arr,n,n1);
	n=n-1;
	printf("elements of the array are: \n");
	for(i=0;i<n;i++)
	printf("%d",arr[i]);}
break;


}
}


